﻿using Download;
using Newtonsoft.Json.Linq;
using StockDataBase;
using StockDataBase.DataOperation;
using StockDataBase.Download;
using StockDataBase.Html;
using StockDataBase.models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 股票数据
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public static MainWindow Instance;

        public MainWindow()
        {
            InitializeComponent();
            Instance = this;
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Utils.DB_Client.CreateTable(typeof(StockInfo));
        }

        private void bt_clear_log_Click(object sender, RoutedEventArgs e)
        {
            listview.Items.Clear();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var bt = sender as Button;
            switch(bt.Content as string)
            {
                case "基本信息" :
                {
                    bt.IsEnabled = false;
                    new Thread(() =>
                    {
                        DownStockInfos.Instance.DownAllStockInfo();
                        Dispatcher.Invoke(() => {
                            bt.IsEnabled = true;
                        });
                        return;
                    }).Start();
                    break;
                }

                case "所有报表" :
                {
                    bt.IsEnabled = false;
                    new Thread(() =>
                    {
                        DownReports.Instance.DownAllReports();
                        Dispatcher.Invoke(() =>
                        {
                            bt.IsEnabled = true;
                        });
                        return;
                    }).Start();
                    break;
                }

                case "报表转入":
                {
                    bt.IsEnabled = false;
                    new Thread(() =>
                    {
                        HtmlParse.Instance.ParseHtmlToDataBase();
                        Dispatcher.Invoke(() =>
                        {
                            bt.IsEnabled = true;
                        });
                        return;
                    }).Start();
                    break;
                }


            }

        }


    }
}
